package com.huawei.esdk.tp.healthcare.local.conference;

import java.util.ArrayList;
import java.util.List;

import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.Holder;
import javax.xml.ws.soap.SOAPFaultException;

import com.huawei.esdk.tp.healthcare.local.MyFaultException;
import com.huawei.esdk.tp.healthcare.local.bean.ConferenceInfo;
import com.huawei.esdk.tp.healthcare.local.impl.autogen.ConfSitesStatusMap;
import com.huawei.esdk.tp.healthcare.local.impl.autogen.TPHealthcareConfCtr;
import com.huawei.esdk.tp.healthcare.local.impl.autogen.TPHealthcareConfMgr;

public class ConferenceImpl implements TPHealthcareConfCtr, TPHealthcareConfMgr {
	
	public static int editScheduledConfResult = 0;
	public static int prolongScheduledConfResult = 0;
	public static int queryConfSitesStatusResult = 0;
	public static int scheduleImmediateConfResult = 0;
	public static int addSiteToScheduledConfResult = 0;
	public static int scheduleDynamicSiteConfResult = 0;
	public static int cancelScheduledConfResult = 0;
	public static int queryConferenceStatusResult = 0;
	public static int delSiteFromScheduledConfResult = 0;
	public static int scheduleConfResult = 0;
	public static int endConfResult = 0;
	public static int addSiteToConfResult = 0;
	public static int delSiteFromConfResult = 0;
	public static int setAudioSwitchResult = 0;
	
	public static boolean throwException = false;
	public static int exceptionCode = 0; 
	
	private SOAPFaultException getSOAPFaultException(){
		SOAPFaultException se = null;
		try {
			SOAPFault fault = new MyFaultException();;
			fault.setFaultCode(String.valueOf(exceptionCode));
			se = new SOAPFaultException(fault);
		} catch (SOAPException e) {
			e.printStackTrace();
		}
		return se;
	}
	
	@Override
	public void editScheduledConf(ConferenceInfo editConf,
			Holder<Integer> addSiteToScheduledConf, Holder<ConferenceInfo> conferenceInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		addSiteToScheduledConf.value = editScheduledConfResult;
		ConferenceInfo conf = new ConferenceInfo();
		conf.setConfId("1234");
		conferenceInfo.value = conf;
		

	}

	@Override
	public Integer prolongScheduledConf(String confId, Integer prolongTime) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return prolongScheduledConfResult;
	}

	@Override
	public void queryConfSitesStatus(String confId, List<String> siteUris,
			Holder<Integer> resultCode,
			Holder<List<ConfSitesStatusMap>> confSitesStatus) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = queryConfSitesStatusResult;
		List<ConfSitesStatusMap> list = new ArrayList<ConfSitesStatusMap>();
		ConfSitesStatusMap map1 = new ConfSitesStatusMap();
		ConfSitesStatusMap map2 = new ConfSitesStatusMap();
		list.add(map1);
		list.add(map2);
		confSitesStatus.value = list;

	}

	@Override
	public void scheduleImmediateConf(ConferenceInfo scheduleConf,
			Holder<Integer> resultCode, Holder<ConferenceInfo> conferenceInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = scheduleImmediateConfResult;
		ConferenceInfo conf = new ConferenceInfo();
		conf.setConfId("1234");
		conferenceInfo.value = conf;
		
	}

	@Override
	public void addSiteToScheduledConf(String confId, String siteUri,
			Holder<Integer> resultCode, Holder<String> accessCode) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = addSiteToScheduledConfResult;
		accessCode.value = "123456";

	}

	@Override
	public Integer cancelScheduledConf(String confId) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return cancelScheduledConfResult;
	}

	@Override
	public void queryConferenceStatus(String confId,
			Holder<Integer> resultCode, Holder<Integer> conferenceStatus) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = queryConferenceStatusResult;
		conferenceStatus.value = 1;

	}

	@Override
	public Integer delSiteFromScheduledConf(String confId, String siteUri) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return delSiteFromScheduledConfResult;
	}

	@Override
	public void scheduleDynamicSiteConf(ConferenceInfo scheduleConf,
			Holder<Integer> resultCode, Holder<ConferenceInfo> conferenceInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = scheduleDynamicSiteConfResult;
		ConferenceInfo conf = new ConferenceInfo();
		conf.setConfId("1234");
		conferenceInfo.value = conf;

	}

	@Override
	public void scheduleConf(ConferenceInfo scheduleConf,
			Holder<Integer> resultCode, Holder<ConferenceInfo> conferenceInfo) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		resultCode.value = scheduleConfResult;
		ConferenceInfo conf = new ConferenceInfo();
		conf.setConfId("1234");
		conferenceInfo.value = conf;
	}

	@Override
	public Integer endConf(String confId) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return endConfResult;
	}

	@Override
	public Integer addSiteToConf(String confId, String siteUri) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return addSiteToConfResult;
	}

	@Override
	public Integer delSiteFromConf(String confId, String siteUri) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return delSiteFromConfResult;
	}

	@Override
	public Integer setAudioSwitch(String confId, Boolean onOff) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return setAudioSwitchResult;
	}

}
